package com.liuwei.classy.controller;

import com.liuwei.classy.controller.header.CommonHeader;
import com.liuwei.classy.util.pub.tool.ResponseTools;
import com.liuwei.classy.util.pub.tool.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by qingshengzheng on 17/11/18.
 */
public abstract class BaseController {
    @Autowired
    protected HttpServletRequest request;

    protected CommonHeader reduceHeader;

    public CommonHeader getHeader() {
        String a = request.getHeader("uid");
        String b = request.getHeader("mobile");
        reduceHeader = new CommonHeader();
        reduceHeader.setMobile(StringUtils.isNull(b) ? null : b);
        reduceHeader.setUid(StringUtils.isNull(a) ? null : Long.parseLong(a));
        return reduceHeader;
    }

    public String responseJson(Object o) {
        return ResponseTools.get().response(o);
    }
}
